/*
给定一个没有重复数字的序列，返回其所有可能的全排列。


*/
class Solution {
public:
    vector<vector<int>> permute(vector<int>& nums) {
        /*
        vector<vector<int>> res;
        vector<int> item;
        vector<int> left(nums.begin(),nums.end());
        dfs(left,item,res);
        return res;
        */
        vector<vector<int>> res;
        vector<int> range;
        vector<bool> visited(nums.size(),false);
        dfs(res,range,visited,nums);
        return res;
    }

private:
    void dfs(vector<vector<int>>& record,vector<int>& range,vector<bool>& visited,vector<int>& nums){
        if(range.size()==nums.size()){
            record.push_back(range);
            return ;
        }
        for(int i=0;i<nums.size();i++){
            if(!visited[i]){
                //cout<<"i:"<<i<<" num:"<<nums[i]<<endl;
                visited[i]=true;
                range.push_back(nums[i]);
                dfs(record,range,visited,nums);
                range.pop_back();
                visited[i]=false;
            }
        }
    } 
    /*
    void dfs(vector<int>& left,vector<int>& item,vector<vector<int>>& res){
        
        if(left.size()==0){
            res.push_back(item);
            return;
        }
        for(int i=0;i<left.size();i++){
            int tmp=left[i];
            left.erase(left.begin()+i);
            item.push_back(tmp);
            dfs(left,item,res);
            left.insert(left.begin()+i,tmp);
            item.pop_back();
        }
    }
    */
};